﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.InventoryItemCategory
{
    public class InventoryItemCategoryPresenter : Presenter<IInventoryItemCategoryView>
    {
        public InventoryItemCategoryPresenter(IInventoryItemCategoryView view)
            : base(view)
        {
        }

        public void Display(string inventoryCategoryId)
        {
            if (inventoryCategoryId == null) return;

            var inventoryItemCategory = Model.GetInventoryItemCategory(inventoryCategoryId);

            View.InventoryCategoryID = inventoryItemCategory.InventoryCategoryID;
            View.InventoryCategoryCode = inventoryItemCategory.InventoryCategoryCode;
            View.InventoryCategoryName = inventoryItemCategory.InventoryCategoryName;
            View.ParentID = inventoryItemCategory.ParentID;
            View.IsParent = inventoryItemCategory.IsParent;
            View.IsMaterial = inventoryItemCategory.IsMaterial;
            View.RestaurantID = inventoryItemCategory.RestaurantID;
            View.Description = inventoryItemCategory.Description;
            View.IsActive = inventoryItemCategory.IsActive;
        }

        public int Save()
        {
            var inventoryItemCategory = new InventoryItemCategoryModel
            {
                InventoryCategoryID = View.InventoryCategoryID,
                InventoryCategoryCode = View.InventoryCategoryCode,
                InventoryCategoryName = View.InventoryCategoryName,
                ParentID = View.ParentID,
                IsParent = View.IsParent,
                IsMaterial = View.IsMaterial,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (inventoryItemCategory.InventoryCategoryID == null)
                return Model.AddInventoryItemCategory(inventoryItemCategory);
            else
                return Model.UpdateInventoryItemCategory(inventoryItemCategory);
        }

        public int Delete(string inventoryCategoryId)
        {
            return Model.DeleteInventoryItemCategory(inventoryCategoryId);
        }
    }
}
